package com.bawei.fuxi.ui.friends;

import android.util.Log;

import com.bawei.fuxi.base.mvp.BasePresenter;
import com.bawei.fuxi.entity.BannerEntity;
import com.bawei.fuxi.entity.ResultEntity;
import com.bawei.fuxi.entity.VideoEntity;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.RequestBody;

public class FriendsPresenter extends BasePresenter<FriendsContract.IFriendsView> implements FriendsContract.IFriendsPresenter {
    private FriendsModel mFriendsModel;
    public FriendsPresenter() {
        mFriendsModel = new FriendsModel();
    }

    @Override
    public void video(int currentPage, int pageSize) {
        Log.d("ytx", "video1111: ");
        mFriendsModel.video(currentPage, pageSize)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<VideoEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        mCompositeDisposable.add(d);
                    }

                    @Override
                    public void onNext(VideoEntity videoEntity) {
                        Log.d("ytx", "video2222: ");
                        if(isAttach()){
                            getView().showVideo(videoEntity);
                        }

                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.d("ytx", "video3333: ");
                        if(isAttach()){
                            getView().onError();
                        }
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    @Override
    public void dianzan(int videoId) {
        mFriendsModel.dianzan(videoId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ResultEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        mCompositeDisposable.add(d);
                    }

                    @Override
                    public void onNext(ResultEntity resultEntity) {
                        Log.d("ytx", "video2222: ");
                        if(isAttach()){
                            getView().showDianZan(resultEntity);
                        }

                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.d("ytx", "video3333: ");
                        if(isAttach()){
                            getView().onError();
                        }
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    @Override
    public void guanzhu(RequestBody requestBody) {
        mFriendsModel.guanzhu(requestBody)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ResultEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        mCompositeDisposable.add(d);
                    }

                    @Override
                    public void onNext(ResultEntity resultEntity) {
                        Log.d("ytx", "video2222: ");
                        if(isAttach()){
                            getView().showGuanZhu(resultEntity);
                        }

                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.d("ytx", "video3333: ");
                        if(isAttach()){
                            getView().onError();
                        }
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
